import scrapy


class ZhaopinSpider(scrapy.Spider):
    name = 'zhaopin'
    allowed_domains = ['163.com']
    start_urls = ['https://hr.163.com/api/hr163/position/queryPage']

    def start_requests(self):
        # 重写此方法目的：
        # 1. 发送的是POST
        # 2. 携带请求体

        headers = {
            "Host": "hr.163.com",
            "Content-Type": "application/json;charset=utf-8",
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0"
        }

        body = '{"currentPage":2,"pageSize":10}'

        yield scrapy.Request(url=self.start_urls[0], method='POST', callback=self.parse, headers=headers, body=body)

    def parse(self, response):
        print("-----1>>", response.status, response.url)
        print("-----2>>", response.body.decode())
